package com.example.demo.ribbon;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;

import com.netflix.client.config.IClientConfig;
import com.netflix.loadbalancer.AvailabilityFilteringRule;
import com.netflix.loadbalancer.IPing;
import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.NoOpPing;
import com.netflix.loadbalancer.Server;
import com.netflix.loadbalancer.ServerList;
import com.netflix.loadbalancer.ServerListSubsetFilter;

/**
 * Created on 2019-06-24
 */
public class DefaultRibbonConfig {
    private static final Logger logger = LoggerFactory.getLogger(DefaultRibbonConfig.class);

    @Bean
    public IRule ribbonRule() {
        return new AvailabilityFilteringRule();
    }

    @Bean
    public IPing ribbonPing() {
        return new NoOpPing();
    }


    @Bean
    public ServerList<Server> ribbonServerList(IClientConfig config) {
        logger.debug("========ribbonServerList======");
        MyConfigurationBasedServerList myConfigurationBasedServerList =
                new MyConfigurationBasedServerList(config);
        return myConfigurationBasedServerList;
    }


    @Bean
    public ServerListSubsetFilter serverListFilter() {
        ServerListSubsetFilter filter = new ServerListSubsetFilter();
        return filter;
    }


}
